package com.fbee.smartcommunities.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fbee.smartcommunities.entity.Log;
import com.fbee.smartcommunities.entity.Visitor;
import com.fbee.smartcommunities.service.VisitorService;
import com.fbee.smartcommunities.vo.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-21
 */
@RestController
@RequestMapping("/visitor")
public class VisitorController {

    @Resource
    private VisitorService visitorService;

    // 分页后内容
    @GetMapping("/list")
    public ResultVO<IPage<Visitor>> getPage(Integer pageNo, Integer pageSize, String keyword ,Boolean order) {
        return ResultVO.success(visitorService.getPage(pageNo,pageSize,keyword,order));
    }

    @PostMapping("/changeState")
    public ResultVO<Boolean> changeState(Long id,Boolean state,String key){
        return ResultVO.success(visitorService.changeState(id,state,key),"修改成功");
    }

    @PostMapping("/add")
    public ResultVO<Boolean> addVisitor(Long openId, String name, Boolean sex,String phone, String carId, String purpose, Long visitTimeValue){
        return ResultVO.success(visitorService.addVisitor(openId,name,sex,phone,carId,purpose,visitTimeValue));
    }

    @GetMapping("/getByUid")
    public ResultVO<List<Visitor>> getVisitorsByUid(Long openId){
        return ResultVO.success(visitorService.getVisitorsByUid(openId));
    }
}
